import { CHOOSE_MAP, CLEAR_MAP_LONGITUDE_LATITUDE } from 'Constants/chooseMap';

const initialState = {
  MapLongitude: sessionStorage.getItem('ChooseMapLongitude') || '',
  MapLatitude: sessionStorage.getItem('ChooseMapLatitude') || '',
};

export default function ChooseMapInfo(state = initialState, action) {
  switch (action.type) {
    case CHOOSE_MAP:
      return Object.assign({}, state, {
        MapLongitude: action.mapInfo.chooseMapLongitude,
        MapLatitude: action.mapInfo.chooseMapLatitude,
      });
    case CLEAR_MAP_LONGITUDE_LATITUDE:
      sessionStorage.removeItem('ChooseMapLongitude');
      sessionStorage.removeItem('ChooseMapLatitude');
      return Object.assign({}, state, {
        MapLongitude: '',
        MapLatitude: ''
      });
    default:
      return state;
  }
}

